package com.aliyun.messagemgt.repository;

import com.aliyun.messagemgt.dto.TemplateSmsSign;
import com.aliyun.messagemgt.domain.repository.TemplateSmsSignRepository;
import com.aliyun.messagemgt.repository.mappers.TemplateSmsSignMapper;
import com.aliyun.messagemgt.entities.TemplateSmsSignEntity;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description
 * @Author hzw
 * @Date 2020/12/16 14:58
 * @Version 1.0
 */
@Service
public class TemplateSmsSignMybatisRepository implements TemplateSmsSignRepository {

    @Autowired
    private TemplateSmsSignMapper templateSmsSignMapper;
    @Override
    public List<TemplateSmsSign> getTempltIdSmsSign(int templateId) {
        List<TemplateSmsSignEntity> list = templateSmsSignMapper.getTempltIdSmsSign(templateId);
        List<TemplateSmsSign> data = new ArrayList<>();
        for (TemplateSmsSignEntity templateSmsSignEntity:list){
            TemplateSmsSign templateSmsSign = new TemplateSmsSign();
            BeanUtils.copyProperties(templateSmsSignEntity,templateSmsSign);
            data.add(templateSmsSign);
        }
        return data;
    }

    @Override
    public int updateTempltIdSmsSign(int id) {
        return templateSmsSignMapper.updateTempltIdSmsSign(id);
    }

    @Override
    public int insertTempltIdSmsSign(TemplateSmsSign templateSmsSign) {
        TemplateSmsSignEntity templateSmsSignEntity = new TemplateSmsSignEntity();
        BeanUtils.copyProperties(templateSmsSign,templateSmsSignEntity);
        return templateSmsSignMapper.insertTempltIdSmsSign(templateSmsSignEntity);
    }
}
